package net.zhuike.novel.app.service;

import android.content.Context;

import net.zhuike.novel.app.bean.BookDetail;
import net.zhuike.novel.app.bean.CategoryList;
import net.zhuike.novel.app.bean.RankingList;
import net.zhuike.novel.app.bean.Rankings;
import net.zhuike.novel.app.bean.Recommend;
import net.zhuike.novel.app.bean.RecommendBookList;
import net.zhuike.novel.app.bean.TabModel;
import net.zhuike.novel.app.bean.TabModelResult;
import net.zhuike.novel.app.ui.base.Constant;
import net.zhuike.novel.app.ui.utils.SharedPreferencesUtil;
import net.zhuike.novel.app.ui.view.UeDialog;

import java.util.Map;

import framework.common.zanetwork.UeHttpUrl;
import framework.common.zanetwork.core.HttpCallback;
import framework.common.zanetwork.core.ResponseCallback;
import okhttp3.Response;

/**
 * Created by qi.wang on 2017/6/12.
 * 书城service
 */

public class BookStoreService extends BaseService{
    public static  void getGender(final Context context, Map<String, Object> parmas, final ResponseCallback<RankingList> callback){
        httpHelper.get(UeHttpUrl.gender(), null, new HttpCallback<RankingList>() {
            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onSuccess(Response response, RankingList o) {
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
    public static  void getCategoryList(final Context context, String id, final ResponseCallback<CategoryList> callback){
        httpHelper.get(UeHttpUrl.getCategoryList()+id, null, new HttpCallback<CategoryList>() {
            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onSuccess(Response response, CategoryList o) {
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
    public static  void getTab(final Context context, String id, final ResponseCallback<TabModelResult> callback){
        categroyHelper.get(UeHttpUrl.getCategoryList()+id, null, new HttpCallback<TabModelResult>() {
            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onSuccess(Response response, TabModelResult o) {
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
    public static  void getRankList(final Context context,String id, final ResponseCallback<Rankings> callback){
        httpHelper.get(UeHttpUrl.getRankList()+id+"/novels/"+ SharedPreferencesUtil.getInstance().getString(Constant.TopCategoryId), null, new HttpCallback<Rankings>() {
            @Override
            public void onRequestBefore() {
                UeDialog.showprogressDialog(context,"","获取中..",false);
            }

            @Override
            public void onSuccess(Response response, Rankings o) {
                UeDialog.hideProgress();
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                UeDialog.hideProgress();
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
    public static  void getBookDetail(final Context context,String id, final ResponseCallback<BookDetail> callback){
        httpHelper.get(UeHttpUrl.getBookDetail()+id, null, new HttpCallback<BookDetail>() {
            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onSuccess(Response response, BookDetail o) {
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
    public static  void getRecommendBookList(final Context context,String id, String type,final ResponseCallback<RecommendBookList> callback){
        httpHelper.get(UeHttpUrl.getRecommendBookList(id), null, new HttpCallback<RecommendBookList>() {
            @Override
            public void onRequestBefore() {

            }

            @Override
            public void onSuccess(Response response, RecommendBookList o) {
                callback.onSuccess(o);
            }

            @Override
            public void onError(Response response, int errorCode, Exception e) {
                callback.onError(response, errorCode, null, e);

            }

            @Override
            public void onFailure(Response response, String failureMsg, int code) {
                callback.onError(response, code, failureMsg, null);
            }
        });
    }
}
